package com.itheima.controller;



import com.itheima.common.JsonResult;
import com.itheima.common.SnowFlake;
import com.itheima.pojo.client.SelectSetmealByCategoryIdAndStatusVo;
import com.itheima.pojo.client.selectSetmealDishByIdVo.SelectSetmealDishByIdVo;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author ChenJunJie
 * @date 2022/6/18 17:23
 * 套餐模块controller层
 */
@RestController
@RequestMapping(value = "/setmeal", produces = "application/json;charset=utf-8")
public class SetmealController {

    @Autowired
    private SnowFlake snowFlake;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    private SetmealService setmealService;

    //通过套餐id查询菜品(菜品详情 )
    @GetMapping("/dish/{id}")
    public JsonResult<List<SelectSetmealDishByIdVo>> selectSetmealDishById(@PathVariable("id") String setmealId){
        List<SelectSetmealDishByIdVo> dishList = setmealService.selectSetmealDishById(setmealId);

        if (dishList!=null){
            return JsonResult.select(dishList, "查询成功");
        }else {
            return JsonResult.error("暂无数据");
        }
    }

    //通过分类id与状态查询套餐
    @GetMapping("/list")
    public JsonResult<List<SelectSetmealByCategoryIdAndStatusVo>> selectSetmealByCategoryIdAndStatus(@RequestParam("categoryId") String categoryId, @RequestParam("status") Integer status){
        List<SelectSetmealByCategoryIdAndStatusVo> setmealList= setmealService.selectSetmealByCategoryIdAndStatus(categoryId,status);

        if (setmealList.size()>0){
            return JsonResult.select(setmealList,"查询成功");
        }else {
            return JsonResult.error("暂无数据");
        }
    }

}
